﻿using System;
using System.Collections.Generic;
using System.IO;

namespace Ngram
{
    public class Data
    {
        public static Dictionary<string, Dictionary<string, double>> P_One = new Dictionary<string, Dictionary<string, double>>();
        public static Dictionary<string, Dictionary<string, double>> P_Two = new Dictionary<string, Dictionary<string, double>>();
        public static Dictionary<string, Dictionary<string, double>> P_Three = new Dictionary<string, Dictionary<string, double>>();
        public static Dictionary<string, Dictionary<string, double>> F = new Dictionary<string, Dictionary<string, double>>();

        public static bool AllowFilter { get; set; }
        public static int ThresholdFilter { get; set; }
        public static double ThresholdNotFound { get; set; }

        public static void readData(string path)
        {
            StreamReader sr = new StreamReader(path + @"\P_One.txt");
            Dictionary<string, double> pp;
            string str;
            while ((str = sr.ReadLine()) != null)
            {
                string[] ppp = str.Split(':');
                string[] pppp = ppp[1].Split('\t');
                pp = new Dictionary<string, double>();
                foreach (string s in pppp)
                {
                    string[] ppppp = s.Split('%');
                    pp.Add(ppppp[0], double.Parse(ppppp[1]));
                }
                P_One.Add(ppp[0], pp);
            }
            sr.Close();
            sr = new StreamReader(path + @"\P_Two.txt");
            while ((str = sr.ReadLine()) != null)
            {
                string[] ppp = str.Split(':');
                string[] pppp = ppp[1].Split('\t');
                pp = new Dictionary<string, double>();
                foreach (string s in pppp)
                {
                    string[] ppppp = s.Split('%');
                    pp.Add(ppppp[0], double.Parse(ppppp[1]));
                }
                P_Two.Add(ppp[0], pp);
            }
            sr.Close();
            sr = new StreamReader(path + @"\P_Three.txt");
            while ((str = sr.ReadLine()) != null)
            {
                string[] ppp = str.Split(':');
                string[] pppp = ppp[1].Split(';');
                pp = new Dictionary<string, double>();
                foreach (string s in pppp)
                {
                    string[] ppppp = s.Split('-');
                    pp.Add(ppppp[0], double.Parse(ppppp[1]));
                }
                P_Three.Add(ppp[0], pp);
            }
            sr.Close();
            sr = new StreamReader(path + @"\F.txt");
            while ((str = sr.ReadLine()) != null)
            {
                string[] ppp = str.Split(':');
                string[] pppp = ppp[1].Split('\t');
                pp = new Dictionary<string, double>();
                foreach (string s in pppp)
                {
                    string[] ppppp = s.Split('%');
                    pp.Add(ppppp[0], double.Parse(ppppp[1]));
                }
                F.Add(ppp[0], pp);
            }
            sr.Close();
        }
        public static void view()
        {
                foreach (KeyValuePair<string,double> i in F["xin chao"])
                {
                    Console.WriteLine(i.Key+" = "+i.Value);
                }
        }
    }
}
